package mid.股票问题.买卖股票的最佳时机Ⅱ;

import java.util.Arrays;

/**
 * @author zhengTao
 * @version 1.0
 * @description: 买卖股票的最佳时机 II
 * @date 2022/11/20 14:48
 */
public class Demo122 {
    public static void main(String[] args) {
        int[] ints=new int[]{7,1,5,3,6,4};
        int i = maxProfit(ints);
        System.out.println(i);
    }
    public static int maxProfit(int[] prices) {
        if(prices.length==1){
            return 0;
        }
        int[] ints = new int[prices.length-1];
        for (int i = 0; i < ints.length; i++) {
            ints[i]=prices[i+1]-prices[i];
        }
        return Arrays.stream(ints).filter(s -> s > 0).sum();
    }
}
